package timer

import systime "time"

type TimerTick struct {
	timerBase
	timer *systime.Ticker
}

func NewTimerTick() ITimer {
	return &TimerTick{}
}

func (_this *TimerTick) Start(sender interface{}) {
	_this.setSender(sender)
	if _this.timer == nil {
		_this.timer = systime.NewTicker(systime.Duration(0))
	} else {
		_this.timer.Reset(systime.Duration(_this.milSecond))
	}
	go _this.elapsed()
}

func (_this *TimerTick) Stop() bool {
	if _this.timer != nil {
		_this.timer.Stop()
		return true
	}
	return true
}

func (_this *TimerTick) elapsed() {
	_this.riseEvent(<-_this.timer.C)
}
